package com.demo.connectdbtest.datasourceconfig;
//
//import com.alibaba.fastjson.JSONObject;
//import org.apache.ibatis.session.SqlSessionFactory;
//import org.mybatis.spring.SqlSessionFactoryBean;
//import org.mybatis.spring.SqlSessionTemplate;
//import org.mybatis.spring.annotation.MapperScan;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.boot.context.properties.ConfigurationProperties;
//import org.springframework.boot.jdbc.DataSourceBuilder;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.core.io.Resource;
//import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
//import org.springframework.jdbc.datasource.DataSourceTransactionManager;
//import org.springframework.transaction.PlatformTransactionManager;
//
//import javax.sql.DataSource;
//import java.util.Arrays;
//
///**
// * 描述：
// *
// * @author: chengc
// * @date 2021/03/31
// */
//@Configuration
//@MapperScan(basePackages = "com.demo.connectdbtest.module.*.slaveMapper", sqlSessionTemplateRef="cmsSqlSessionTemplate")
//public class ConfigurationDatasourceSlave {
//    private static final Logger log = LoggerFactory.getLogger(ConfigurationDatasourceSlave.class);
//
//    @Bean(name = "cmsDataSource")
//    @ConfigurationProperties("spring.datasource.slave")
//    public DataSource slaveDataSource(){
//        return DataSourceBuilder.create().build();
//    }
//
//    @Bean(name = "cmsSqlSessionFactory")
//    public SqlSessionFactory sqlSessionFactory(@Qualifier("cmsDataSource") DataSource dataSource) throws Exception {
//        SqlSessionFactoryBean sessionFactoryBean = new SqlSessionFactoryBean();
//        sessionFactoryBean.setDataSource(dataSource);
//        Resource[] resources = new PathMatchingResourcePatternResolver().getResources("classpath*:mapper/slaveMapper/*.xml");
//        //System.out.println("mapperLocaltion======"+ JSONObject.toJSONString(resources));
//        sessionFactoryBean.setMapperLocations(resources);
//        return sessionFactoryBean.getObject();
//    }
//    @Bean(name = "cmsTransactionManager")
//    public PlatformTransactionManager mangoTransactionManager(@Qualifier("cmsDataSource") DataSource dataSource) {
//        return new DataSourceTransactionManager(dataSource);
//    }
//    @Bean(name = "cmsSqlSessionTemplate")
//    public SqlSessionTemplate mangoSqlSessionTemplate(@Qualifier("cmsSqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception {
//        return new SqlSessionTemplate(sqlSessionFactory);
//    }
//}
